//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.qst.crop.service.impl;

import com.qst.crop.dao.PurchaseDao;
import com.qst.crop.entity.Purchase;
import com.qst.crop.model.MyPurchase;
import com.qst.crop.service.PurchaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PurchaseServiceImpl implements PurchaseService {
    @Autowired
    private PurchaseDao purchaseDao;

    public PurchaseServiceImpl() {
    }

    public void add(Purchase purchase) {
        this.purchaseDao.insertSelective(purchase);
    }

    public List<MyPurchase> selectByPurchaseType() {
        UserDetails principal = (UserDetails)SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        String name = principal.getUsername();
        System.out.println("查询订单：");
        List<MyPurchase> purchases = this.purchaseDao.selectByPurchase(name);
        System.out.println(purchases);
        return purchases;
    }

    public Purchase selectNewPurchaseId(String ownName) {
        Purchase purchase = this.purchaseDao.selectNewPurchaseId(ownName);
        return purchase;
    }
}
